﻿
#include "pch.h"
#pragma data_seg ("myseg")
int i = 0;
char a[32] = "hello world";
#pragma data_seg()
BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
		//MessageBox(0, L"Calling", L"Calling", MB_OK);
		break;
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}
INT32 _stdcall VBstdin() {
	return (INT32)stdin;
}
INT32 _stdcall VBstdout() {
	return (INT32)stdout;
}
void _stdcall WriteToConsole(char* outstr,int length) {
	if (!AttachConsole(ATTACH_PARENT_PROCESS)) {
		AllocConsole();
	}
	char buffer[128];
	memcpy(buffer, outstr, sizeof(char)*length);
	freopen("CONOUT$", "w", stdout);
	freopen("CONIN$", "r", stdin);
	printf("%s\n",buffer);
}
void _stdcall ReadFromConsole(char* instr) {
	if (!AttachConsole(ATTACH_PARENT_PROCESS)) {
		AllocConsole();
	}
	char buffer[128];
	memset(&buffer, 0, sizeof(char) * 128);
	freopen("CONOUT$", "w", stdout);
	freopen("CONIN$", "r", stdin);
	scanf("%s", &buffer);
	memcpy(instr, buffer,sizeof(char)*strlen(buffer));
}